package tacocloud.dao;

import lombok.Data;
import org.hibernate.validator.constraints.CreditCardNumber;

import javax.validation.constraints.Digits;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Pattern;
import java.util.Date;

/**
 * 通过注解对输入的值进行限制
 */
@Data
public class Order {

    private Long id;
    
    private Date placedAt;

    @NotBlank(message = "Name is required") //确保用没有提交空白字段
    private String name;

    @NotBlank(message = "Street is required")
    private String street;

    @NotBlank(message = "City is required")
    private String city;

    @NotBlank(message = "State is required")
    private String state;

    @NotBlank(message = "Zip code is required")
    private String zip;

    @CreditCardNumber(message = "Not a valid credit card number")   // 必须是个合法的信用卡号，能通过Luhn算法检查
    private String ccNumber;

    @Pattern(regexp = "^(0[1-9]|1[0-2])([\\/])([1-9][0-9])$",
             message = "Must be formatted MM/YY")   // 正则表达式
    private String ccExpiration;

    @Digits(integer = 3,fraction = 0,message = "Invalid CVV")   // 确保数值包含三位数字
    private String ccCVV;
}
